package yz_handler

import (
	"fmt"
	"net/http"
	"peilian-api/app/global/bind"
	"peilian-api/app/global/log"
	"peilian-api/app/services/yz_service"
	"peilian-api/utils/format"

	"github.com/gin-gonic/gin"
)

func OrderInfoApiCall(ctx *gin.Context) {
	var mr yz_service.ParamBaseReq
	if err := bind.ShouldBinding(ctx, &mr); err != nil {
		log.Logger.InfoMsgF(ctx, "【yz-msg】 param binding is error")
		ctx.JSON(http.StatusOK, gin.H{
			"code": 0,
			"data": struct{}{},
			"msg":  "success",
		})
		return
	}
	err := new(yz_service.Bs).YzMessageCall(ctx, mr)
	// 解析消息头
	if err != nil {
		log.Logger.InfoMsgF(ctx, "bid:【"+mr.Id+"】,"+err.Error())
	}
	// 统一返回成功
	ctx.JSON(http.StatusOK, gin.H{
		"code": 0,
		"data": struct{}{},
		"msg":  "success",
	})
}

func YzApiToken(ctx *gin.Context) {
	token, _ := new(yz_service.YzApi).GetAccessTokenApi(ctx)
	token, err := new(yz_service.YzApi).DecryptSingle(ctx, "$OX//CBIjcAFGaOf0/+9dlg==$1$", token)
	// 解析消息头
	if err != nil {
		log.Logger.InfoF(ctx, fmt.Sprintf("call error:%v", err))
	}
	// 统一返回成功
	ctx.JSON(http.StatusOK, gin.H{
		"code": 0,
		"data": token,
		"msg":  "success",
	})
}

// 获取微商店，上架商品信息
func YzGetItemList(ctx *gin.Context) {
	out, err := new(yz_service.Bs).YzItemsSearch(ctx)
	if err != nil {
		format.NewResponseJson(ctx).Error(20001, err.Error())
		return
	}
	format.NewResponseJson(ctx).SuccessObj(out)
}
